home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7791 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: nwgw.infi.net!usenet
  2. From: Steve Rountree <srndtree@infi.net>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pattern matching in C
  5. Date: Wed, 28 Feb 1996 18:24:53 -0800
  6. Organization: InfiNet
  7. Message-ID: <31350E75.3DBD@infi.net>
  8. References: <4gjo68$jpp@paperboy.ids.net> <31349B7D.167E@mozart.bme.ohio-state.edu>
  9. NNTP-Posting-Host: h-bookplate.dc.infi.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b5 (Win16; I)
  14.  
  15. scarney wrote:
  16. > >
  17. > > I'm trying to do some text file pattern matching. Using a simple while
  18. > > loop that has a <data> != <j.random string> in its conditional doesn't
  19. > > work. Depending on different ways of doing it, you get a segmentation
  20. > > fault, random output, or no output.
  21. > >
  22. > > Anybody know how I SHOULD be doing this?
  23.  
  24.   Assuming both <data> and <j.random string> are both character arrays or 
  25.  pointers to characters then I would think that:
  26.  
  27.    #include<string.h>
  28.     .
  29.     .
  30.     .
  31.  
  32.   if(strcmp(data,j.random_string)){ /* if you are looking for non-match 
  33. */
  34.     do something;
  35.   }
  36.  
  37.  should work for you.  A segment violation I believe would indicate that 
  38. you have an unintialized pointer or array in your comparison.
  39.  
  40.  
  41. Steve Rountree
  42.